package com.htgd.gardenexpo.controller;


import com.htgd.gardenexpo.dto.GeConFreeSportsDTO;
import com.htgd.gardenexpo.dto.StatusDTO;
import com.htgd.gardenexpo.entity.CommonResult;
import com.htgd.gardenexpo.service.IGeConFreeSportsTaskService;
import com.htgd.gardenexpo.utils.TokenUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 * 自由跑任务 前端控制器
 * </p>
 *
 * @author author
 * @since 2025-04-02
 */
@RestController
@RequestMapping("/api/freeSportsTask")
@Api(tags = "自由跑任务")
@Slf4j
public class GeConFreeSportsTaskController {

    @Autowired
    private IGeConFreeSportsTaskService geConFreeSportsTaskService;

    @PostMapping(value = "/add")
    @ApiOperation("添加")
    public CommonResult add(HttpServletRequest request) {
        String accessToken = request.getHeader("Access_token");
        String openId = TokenUtil.getUsernameFromToken(accessToken);
        log.info("自由跑任务-添加：{}",openId);
        return geConFreeSportsTaskService.add(openId);
    }

    @PostMapping(value = "/changeStatus")
    @ApiOperation("改变状态")
    public CommonResult changeStatus(@RequestBody StatusDTO statusDTO) {
        log.info("自由跑任务-改变状态：{}",statusDTO);
        return geConFreeSportsTaskService.changeStatus(statusDTO);
    }

}
